package day05;

import java.util.Arrays;
import java.util.Comparator;
import java.util.Random;

public class sortArray {
    public static void main(String[] args) {
        Integer[] arr1 = getArray(10);
        printArray(arr1);
        Arrays.sort(arr1);
        System.out.println("升序打印");
        printArray(arr1);
        System.out.println("=============");
        Arrays.sort(arr1, new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o2 - o1;
            }
        });
        System.out.println("降序打印");
        printArray(arr1);
    }

    public static Integer[] getArray(int index) {
        Random r = new Random();
        Integer[] arr = new Integer[index];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = r.nextInt(100);
        }
        return arr;
    }

    public static void printArray(Integer[] arr) {
        System.out.print("[");
        for (int i = 0; i < arr.length; i++) {
            if (i == arr.length - 1) {
                System.out.print(arr[i]);
            } else {
                System.out.print(arr[i] + ", ");
            }
        }
        System.out.print("]");
        System.out.println();
    }
}
